package vip.xiaomaoxiaoke.functiondemo.msg.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import vip.xiaomaoxiaoke.functiondemo.msg.repository.LocalMessageTable;
import vip.xiaomaoxiaoke.functiondemo.msg.mapper.BarrierGateFlashingRecordMapper;
import vip.xiaomaoxiaoke.functiondemo.msg.repository.LocalMessageRepository;

import java.util.List;

@Service
public class MySqlLocalMessageRepositoryImpl implements LocalMessageRepository {

    @Autowired
    private BarrierGateFlashingRecordMapper barrierGateFlashingRecordMapper;

    @Override
    public void save(LocalMessageTable message) {
        barrierGateFlashingRecordMapper.insert(message);
    }

    @Override
    public void update(LocalMessageTable message) {
        barrierGateFlashingRecordMapper.updateById(message);
    }

    @Override
    public List<LocalMessageTable> loadNotSuccessByUpdateGt(long id, int size) {
        LambdaQueryWrapper<LocalMessageTable> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.orderByAsc(LocalMessageTable::getId);
        lambdaQueryWrapper.gt(LocalMessageTable::getId,id);
        lambdaQueryWrapper.ne(LocalMessageTable::getState,1);
        lambdaQueryWrapper.ne(LocalMessageTable::getRefusalStrategiesState,0);
        lambdaQueryWrapper.apply("retry_count <= max_retries");
        lambdaQueryWrapper.last("limit "+size);
        return barrierGateFlashingRecordMapper.selectList(lambdaQueryWrapper);

    }
}
